package String;

public class 字符串乘法 {
    public String multiply(String num1, String num2) {
        if (num1.equals("0") || num2.equals("0")) return "0";
        int len1 = num1.length();
        int len2 = num2.length();
        int len = len1 + len2 - 1;
        int[] res = new int[len];
        for (int i = len1 - 1; i >= 0; i--) {
            int value1 = num1.charAt(i) - '0';
            for (int j = len2 - 1; j >= 0; j--) {
                int value2 = num2.charAt(j) - '0';
                int multi = value1 * value2;
                res[i + j] += multi;
            }
        }
        for (int i = len - 1; i >= 1; i--) {
            int temp = res[i];
            res[i] = temp % 10;
            res[i - 1] += temp / 10;
        }
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < res.length; i++) {
            if (i == 0 && res[i] == 0) continue;
            result.append(res[i]);
        }
        return result.toString();
    }
}
